package com.yupi.springbootinit.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.springbootinit.mapper.BookMapper;
import com.yupi.springbootinit.model.dto.book.BookQueryRequest;
import com.yupi.springbootinit.model.entity.Book;
import com.yupi.springbootinit.model.vo.BookVO;
import com.yupi.springbootinit.service.BookService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author wzhRoot
* @description 针对表【book】的数据库操作Service实现
* @createDate 2023-12-16 16:10:06
*/
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book>
    implements BookService {

    @Override
    public QueryWrapper<Book> getQueryWrapper(BookQueryRequest bookQueryRequest) {
        return null;
    }

    @Override
    public Page<BookVO> getBookVOPage(Page<Book> bookPage, HttpServletRequest request) {
        List<Book> bookList = bookPage.getRecords();
        Page<BookVO> bookVOPage = new Page<>(bookPage.getCurrent(), bookPage.getSize(), bookPage.getTotal());
        if (CollectionUtils.isEmpty(bookList)) {
            return bookVOPage;
        }
        List<BookVO> collect = bookList.stream().map(book -> {
            BookVO bookVO = BookVO.objToVo(book);
            return bookVO;
        }).collect(Collectors.toList());
        bookVOPage.setRecords(collect);
        return bookVOPage;
    }

}




